package com.syqc.adapter

import android.content.Context
import android.view.View
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import androidx.core.view.isVisible
import com.syqc.custom.LeftRightTextView
import com.syqc.entity.AddOilFee
import com.syqc.entity.BaseFee
import com.syqc.entity.InsureFee
import com.syqc.entity.RepairFee
import com.syqc.entity.TrafficFee
import com.syqc.monitor.R

/**
 *@Author Jasper
 *@Time   2020/10/21
 *@Desc   费用详情
 */
class FeeInfoAdapter<Y : BaseFee>(mContext: Context, private val type: String) :
    BaseQuickAdapter<Y, BaseViewHolder>(R.layout.item_fee_info) {
    private val rmbUnit = mContext.getString(R.string.unit_rmb)
    private val priceUnit = mContext.getString(R.string.unit_oil_price)
    private val riseUnit = mContext.getString(R.string.unit_rise)
    private val mileUnit = mContext.getString(R.string.unit_mile)

    override fun convert(holder: BaseViewHolder, item: Y) {
        item.let {
            val lrTvFeeOne = holder.getView<LeftRightTextView>(R.id.lrTvFeeOne)
            val lrTvFeeTwo = holder.getView<LeftRightTextView>(R.id.lrTvFeeTwo)
            val lrTvFeeThree = holder.getView<LeftRightTextView>(R.id.lrTvFeeThree)
            val lrTvFeeFour = holder.getView<LeftRightTextView>(R.id.lrTvFeeFour)
            val lrTvFeeFive = holder.getView<LeftRightTextView>(R.id.lrTvFeeFive)
            val lrTvFeeSix = holder.getView<LeftRightTextView>(R.id.lrTvFeeSix)
            val lrTvFeeSeven = holder.getView<LeftRightTextView>(R.id.lrTvFeeSeven)
            val lrTvFeeEight = holder.getView<LeftRightTextView>(R.id.lrTvFeeEight)
            val lrTvFeeNine = holder.getView<LeftRightTextView>(R.id.lrTvFeeNine)
            val lrTvFeeTen = holder.getView<LeftRightTextView>(R.id.lrTvFeeTen)
            val lrTvFeeEleven = holder.getView<LeftRightTextView>(R.id.lrTvFeeEleven)
            val llFeeOneThree = holder.getView<LinearLayout>(R.id.ll_fee_ont_three)
            val position = holder.layoutPosition + 1
            val num = if (position < 10) "0$position" else "$position"
            holder.setText(R.id.tv_item_num, num)
            when (type) {

                "FeeAddOil" -> {
                    val addOilFee = it as AddOilFee.InfoEntity
                    lrTvFeeOne.setLeftTitle(R.string.desc_oil_date)
                    lrTvFeeTwo.setLeftTitle(R.string.desc_add_oil_type)
                    lrTvFeeThree.setLeftTitle(R.string.desc_add_oil_use)
                    lrTvFeeFour.setLeftTitle(R.string.desc_price_oil)
                    lrTvFeeNine.setLeftTitle(R.string.desc_run_mile)
                    lrTvFeeTen.isVisible=false

                    lrTvFeeOne.setRightText(addOilFee.feeDate)
                    lrTvFeeTwo.setRightText("${addOilFee.oilType} ")
                    lrTvFeeThree.setRightText("${addOilFee.capacity} $riseUnit")
                    lrTvFeeFour.setRightText("${addOilFee.unitPrice} $priceUnit")
                    lrTvFeeEleven.setRightText("${addOilFee.totalFee} $rmbUnit")
                    lrTvFeeNine.setRightText("${addOilFee.mile} $mileUnit")
                    holder.setText(R.id.tvFeeAddrValue, isNoRemark(addOilFee.remark))
                }
                "FeeRepair" -> {
                    val repairFee = it as RepairFee.InfoEntity
                    lrTvFeeOne.setLeftTitle(R.string.desc_date_repair)
                    lrTvFeeTwo.setLeftTitle(R.string.desc_fee_time)
                    lrTvFeeThree.setLeftTitle(R.string.desc_fee_manger)
                    lrTvFeeFour.setLeftTitle(R.string.desc_fee_parts)
                    lrTvFeeNine.setLeftTitle(R.string.desc_fee_add)

                    lrTvFeeOne.setRightText(repairFee.feeDate)
                    lrTvFeeTwo.setRightText("${repairFee.manHourFee} $rmbUnit")
                    lrTvFeeThree.setRightText("${repairFee.manageFee} $rmbUnit")
                    lrTvFeeFour.setRightText("${repairFee.partsFee} $rmbUnit")
                    lrTvFeeNine.setRightText("${repairFee.procFee} $rmbUnit")
                    lrTvFeeTen.setRightText("${repairFee.othreFee} $rmbUnit")
                    lrTvFeeEleven.setRightText("${repairFee.totalFee} $rmbUnit")
                    val driver = holder.getView<LeftRightTextView>(R.id.lrTvFeeDriver)
                    val person = holder.getView<LeftRightTextView>(R.id.lrTvFeePerson)
                    driver.isVisible=true
                    person.isVisible=true
                    driver.setRightText(repairFee.driverName?:"")
                    person.setRightText(repairFee.person?:"")
                    holder.setText(R.id.tvFeeAddrValue, isNoRemark(repairFee.remark))
                }
                "FeeInsure" -> {
                    val insureFee = it as InsureFee.InfoEntity
                    holder.setVisible(R.id.ll_fee_insure, true);
                    llFeeOneThree.isVisible=false

                    lrTvFeeOne.setLeftTitle(R.string.desc_date_year_buy)
                    lrTvFeeNine.setLeftTitle(R.string.desc_fee_business)
                    lrTvFeeTen.setLeftTitle(R.string.desc_fee_strong)

                    lrTvFeeOne.setRightText(insureFee.feeDate)
                    lrTvFeeFive.setRightText(insureFee.insuurCmp)
                    lrTvFeeSix.setRightText(insureFee.insureCode)
                    lrTvFeeSeven.setRightText(insureFee.startDate)
                    lrTvFeeEight.setRightText(insureFee.endDate)
                    lrTvFeeNine.setRightText("${insureFee.syxFee} $rmbUnit")
                    lrTvFeeTen.setRightText("${insureFee.jqxFee} $rmbUnit")
                    lrTvFeeEleven.setRightText("${insureFee.totalFee} $rmbUnit")
                    holder.setText(R.id.tvFeeAddrValue, isNoRemark(insureFee.remark))
                }
                "FeeTraffic" -> {
                    val trafficFee = it as TrafficFee.InfoEntity
                    lrTvFeeOne.setRightText(trafficFee.feeDate)
                    lrTvFeeTwo.setRightText("${trafficFee.highRoadFee} $rmbUnit")
                    lrTvFeeThree.setRightText("${trafficFee.bridgeFee} $rmbUnit")
                    lrTvFeeFour.setRightText("${trafficFee.stopCarFee} $rmbUnit")
                    lrTvFeeNine.setRightText("${trafficFee.washCarFee} $rmbUnit")
                    lrTvFeeTen.setRightText("${trafficFee.otherFee} $rmbUnit")
                    lrTvFeeEleven.setRightText("${trafficFee.totalFee} $rmbUnit")
                    holder.setText(R.id.tvFeeAddrValue, isNoRemark(trafficFee.remark))
                }
                "FeeYearVrf" -> {
                    val yearFee = it as BaseFee
                    llFeeOneThree.isVisible=false
                    lrTvFeeTen.isVisible=false
                    lrTvFeeEleven.isVisible=false

                    lrTvFeeOne.setLeftTitle(R.string.desc_date_year)
                    lrTvFeeOne.setRightText(yearFee.feeDate)
                    lrTvFeeNine.setLeftTitle(R.string.desc_fee_year)
                    lrTvFeeNine.setRightText("${yearFee.totalFee} $rmbUnit")

                    holder.setText(R.id.tvFeeAddrValue, isNoRemark(yearFee.remark))
                }
                "FeeOther" -> {
                    val otherFee = it as BaseFee
                    llFeeOneThree.isVisible=false
                    lrTvFeeNine.isVisible=false
                    lrTvFeeEleven.isVisible=false

                    lrTvFeeOne.setLeftTitle(R.string.desc_date_fee)
                    lrTvFeeOne.setRightText(otherFee.feeDate)
                    lrTvFeeTen.setLeftTitle(R.string.desc_fee_money)

                    lrTvFeeTen.setRightText("${otherFee.totalFee} $rmbUnit")
                    holder.setText(R.id.tvFeeAddrValue, isNoRemark(otherFee.remark))
                }
                else -> {
                }
            }
        }
    }

    fun isNoRemark(remark: String?): String {
        return if (remark.isNullOrEmpty()) {
            context.getString(R.string.desc_no_remark)
        } else {
            remark
        }
    }


}